package com.agent.course.controller;

import com.agent.commons.Result.Result;
import com.agent.commons.errorcode.ControllerErrorCodeConstants;
import com.agent.commons.exception.BaseException;
import com.agent.commons.utils.MinIOUtil;
import com.agent.course.dataobject.ClassBaseDO;
import com.agent.course.param.ClassParam;
import com.agent.course.service.ClassService;
import com.agent.course.vo.ClassMemberVO;
import com.agent.course.vo.TeacherClassVO;
import com.agent.feign.client.UserClient;
import com.agent.feign.entity.Member;
import jakarta.annotation.Resource;
import org.simpleframework.xml.core.Validate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

@RestController
@RequestMapping("/class")
public class ClassController {

    @Autowired
    private ClassService  classService;


    /**
     * 创建班级(教师端)
     */
    @PostMapping("/create")
    public Result<ClassBaseDO> createClass(@RequestPart("classParam") ClassParam classParam, @RequestPart MultipartFile picture) throws Exception {
        if(picture!=null){
            String avatar = MinIOUtil.makeFileName(UUID.randomUUID()+"_"+picture.getOriginalFilename());
            String classAvatar = MinIOUtil.uploadFile("test-one", picture, avatar);
            classParam.setClassAvatar(classAvatar);
        }
        ClassBaseDO classBaseDO = classService.addClass(classParam);
        return Result.success(classBaseDO);
    }

    /**
     * 获取教师创建班级(教师端、管理员端)
     */
    @GetMapping("/get/teacherClass/{userId}")
    public Result<List<TeacherClassVO>> getTeacherClass(@PathVariable String userId){
        return Result.success(classService.getTeacherClasses(userId));
    }

    /**
     * 获取学生参加班级(学生端)
     */
    @GetMapping("/get/studentClass/{userId}")
    public Result<List<TeacherClassVO>> getStudentClass(@PathVariable String userId){
        return Result.success(classService.getStudentClasses(userId));
    }


}
